package com.ayuer.chapter02;

import java.util.Arrays;

public class PascalTriangleDemo {


    private static int element(int i, int j) {
        if (j == 0 || i == j) {
            return 1;
        }
        return element(i - 1, j - 1) + element(i - 1, j);
    }

    private static void print(int n, int[][] res) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= i; j++) {
//                System.out.print(element(i, j) + " ");
                res[i][j] = element(i, j);
                System.out.printf("%-4d", element(i, j));
            }
            System.out.println();
        }

    }

    public static void main(String[] args) {

//        int elemented = element(4, 2);
//        System.out.println(elemented);

        int[][] res = new int[5][5];

        print(5, res);
        for (int i = 0; i < 5; i++) {
            System.out.println(Arrays.toString(res[i]));
        }
    }
}
